package org.example.controller;


import org.example.entity.User;
import org.example.service.MessageProducerService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SendMessageController {


    @Autowired

    MessageProducerService messageProducerService;

    @RequestMapping("/user/{id}/{username}")

    public String createMessageQueue(@PathVariable("id") int id, @PathVariable("username") String username) {
        User user = new User(id, username);
        messageProducerService.psubPublisher(user);
        return "消息已发出";
    }

    @RequestMapping("/test/{message}")

    public String routingPublisher(@PathVariable("message") String message) {
//        String[] m = message.split("&");
//
        messageProducerService.routingPublisher(message);
        return "消息已发出";
    }

    @RequestMapping("/test2/{message}")

    public String routingPublisher2(@PathVariable("message") String message) {
//        String[] m = message.split("&");
//
        messageProducerService.routingPublisher2(message);
        return "消息已发出";
    }


    @RequestMapping("/test3/{key}/{message}")

    public String routingPublisher2(@PathVariable("key") String key, @PathVariable("message") String message) {
//        String[] m = message.split("&");
//
        messageProducerService.routingPublisher3(key, message);
        return "消息已发出";
    }


    @RequestMapping("/topic1/{message}")

    public String topicPublisher1(@PathVariable("message") String message) {
//        String[] m = message.split("&");
//
        String key ="info.email.sms";
        messageProducerService.TopicPublisher(key, message);
        return "消息已发出";
    }


    @RequestMapping("/topic/{key}/{message}")

    public String sendMsg(@PathVariable("key") String key,@PathVariable("message") String message){
        messageProducerService.TopicPublisher(key,message);
        return "发送成功";

    }
}
